package com.rd.common.model;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Map;

@Data
@Accessors(chain = true)
public class Result<T> {
    private Integer code;
    private String message;
    private T data;
    private Map<String,Object> extData;

    public static <T> Result<T> success() {
        return new Result<T>().setCode(200).setMessage("success");
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>().setCode(ResultCode.SUCCESS.getCode()).setMessage("success").setData(data);
    }

    public static <T> Result<T> error() {
        return new Result<T>().setCode(ResultCode.INTERNAL_ERROR.getCode()).setMessage("error");
    }

    public static <T> Result<T> error(Integer code, String message) {
        return new Result<T>().setCode(code).setMessage(message);
    }

    public static <T> Result<T> error(ResultCode resultCode) {
        return new Result<T>().setCode(resultCode.getCode()).setMessage(resultCode.getMessage());
    }
}